<?php 
include_once "../library/Controller.php";

class Map extends Controller
{
	function __construct()
	{
		//important to call initialize superclass
		parent::__construct();

		// use data to store the GET method
		$data 	= $_GET;

		$action = $data['action'];

		$this->folder 	= '../map';
		$this->html		= $data['html'] ? $data['html'] : 'map.htm';
		$this->image	= $data['image'] ? $data['image'] : 'map.gif';
		$this->subfolder	= '';
		$this->imageSrc = '';
		$this->htmlString = '';
	}

	function loadMap($subfolder)
	{
		$map = $this->map;
		$this->subfolder = $subfolder;

		$this->imageSrc = 
			$this->folder . "/" . 
			$subfolder . "/" .
			$this->image;

		$fileContents = file_get_contents("$this->folder/$subfolder/$this->html");

		// clean map file to remain the img,area,map tag
		$mapTag = $this->getElementsByTagName($fileContents, 'map');

		//return $mapTag[1];
		$this->htmlString = $mapTag[1];
	}

	function getAllRegion()
	{
		//$this->htmlString

	}

	// factory function
	function getMap($subfolder)
	{
		$map = new Map();
		$map->loadMap($subfolder);
		return $map;
	}
}

